package com.lingnan.wanxiangxinxun.service.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingnan.wanxiangxinxun.entity.dto.query.Author_queryDTO;
import com.lingnan.wanxiangxinxun.entity.po.Author;
import com.lingnan.wanxiangxinxun.entity.vo.common.PageVO;
import com.lingnan.wanxiangxinxun.mapper.AuthorMapper;
import com.lingnan.wanxiangxinxun.service.IAuthorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author swl
 * @since 2025-04-07
 */
@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, Author> implements IAuthorService {

    @Autowired
    private AuthorMapper authorMapper;

    @Override
    public PageVO<Author> getInCondition(Author_queryDTO authorQueryDTO) {
        Author author = new Author();
        BeanUtils.copyProperties(authorQueryDTO, author);
        long current = authorQueryDTO.getCurrent();
        long size = authorQueryDTO.getSize();

        Page<Author> page = new Page<>(current, size); // 创建分页对象
        Page<Author> page_MP = lambdaQuery()
                .eq(author.getId() != null, Author::getId, author.getId())
                .like(author.getName() != null, Author::getName, author.getName())
                .eq(author.getPhone() != null, Author::getPhone, author.getPhone())
                .eq(author.getEmail() != null, Author::getEmail, author.getEmail())
                .eq(author.getStatus() != null, Author::getStatus, author.getStatus())

                .orderByDesc(Author::getCreateTime)
                .orderByDesc(Author::getWorksNum)
                .page(page); // 应用分页

        return PageVO.of(page_MP);
    }


    //查找--根据id查询
    @Override
    public List<Author> getAuthorListByIds(List<Integer> ids) {
        if (ids == null || ids.isEmpty()){
            return null;
        }
        return authorMapper.getAuthorListByIds(ids);
    }

}
